package com.koron.css2.baseConfig.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.bean.PubSysUserBean;
import com.koron.css2.baseConfig.mapper.PubSysUserMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

/**
 * 岗位用户查询
 * @author bin
 *
 */
public class PostUserQuery implements ServerInterface{

	private static Logger logger = LogManager.getLogger(PostUserQuery.class);
	
	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {

		@SuppressWarnings("rawtypes")
		MessageBean<List> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功", List.class);
		try { 
			String post = JsonUtils.objectToPojo(req.getData(), String.class);
			PubSysUserMapper mapper = factory.getMapper(PubSysUserMapper.class);
			List<PubSysUserBean> users = mapper.selectPubSysUserByPost(post);
			info.setData(users);
		} catch (Exception e) {
			info.setCode(Constant.MESSAGE_INT_FAIL);
			info.setDescription(e.getMessage());
			logger.error(e.getMessage(), e);
		}
		return info;
	}

}
